package com.Humanities.content.api;

import com.xuecheng.base.utils.SecurityUtil;
import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.ICourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courseTeacher")
@Api(value = "课程教师信息管理接口",tags = "课程教师信息管理接口")
public class CourseTeacherController {
    @Autowired
    private ICourseTeacherService courseTeacherService;
    //查询教师接口

    @ApiOperation("查询教师信息")
    @GetMapping("/list/{id}")
    public List<CourseTeacher> getTeacherInfo(@PathVariable Long id) {
        List<CourseTeacher> list = courseTeacherService.getTeacherInfo(id);
        return list;
    }

    //添加或者修改教师接口
    @PostMapping
    public CourseTeacher addCourseTeacher(@RequestBody  @Validated CourseTeacher courseTeacher){
        //取出用户身份
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        //机构id
        String companyId = user.getCompanyId();
        return courseTeacherService.saveOrUpdate(Long.parseLong(companyId),courseTeacher);
    }

    //删除教师接口
    @DeleteMapping("/course/{courseId}/{id}")
    public void deleteCourseTeacher(@PathVariable Long courseId,@PathVariable Long id){
        //取出用户身份
        SecurityUtil.XcUser user = SecurityUtil.getUser();
        //机构id
        String companyId = user.getCompanyId();
         courseTeacherService.deleteCourseTeacher(Long.parseLong(companyId),courseId,id);
    }


}
